// import { from } from 'core-js/fn/array'
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import { getItem } from '../utils/storage'
// import Login from '../views/login'
// import Setting from '../views/setting'
// import NotFound from '../views/404.vue'
// import LogesticsInformation from '../views/logisticsInformation'
// import MapInformation from '../views/mapInformation'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/index.vue')
  },
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      {
        path: 'logestics',
        name: 'LogesticsInformation',
        // component: LogesticsInformation
        component: () => import('../views/logisticsInformation/index.vue')
      },
      {
        path: 'setting',
        name: 'Setting',
        component: () => import('../views/setting/index.vue')
      },
      {
        path: 'map',
        name: 'MapInformation',
        component: () => import('../views/mapInformation/index.vue')
      },
      {
        path: 'courier',
        name: 'Courier',
        component: () => import('../views/CourierInformation/index.vue')
      },
      {
        path: 'company',
        name: 'Company',
        component: () => import('../views/companyManagement/index.vue')
      }
    ]
  },
  {
    path: '/data',
    name: 'DataShow',
    component: () => import('../views/dataShow/index.vue')
  },
  {
    path: '*',
    component: () => import('../views/404.vue')
  }
]

const router = new VueRouter({
  routes
})
// 添加路由守卫
router.beforeEach((to, from, next) => {
  var jti = getItem('userInfo').jti
  if (to.path !== '/login' && !jti) next({ path: '/login' })
  // 如果用户未能验证身份，则 `next` 会被调用两次
  next()
})

export default router
